package 华为OD机试B卷复用题.基础题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class HJ11_用连续自然数之和来表达整数 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试B卷复用题/基础题/input/11.txt"));
        MyUtil.START();
        Solution(in);
        MyUtil.END();
    }

    // 滑动窗口
    static void Solution(Scanner in) {
        int N = in.nextInt();
        int right = N;
        int left = N;
        int tmp = right;
        int res = 0;
        while (left <= right && right > 0) {
            if (tmp > N) {
                tmp -= right;
                right--;
            } else if (tmp < N) {
                left--;
                tmp += left;
            } else if (tmp == N) {
                res++;
                System.out.print(N + "=");
                for (int i = left; i <= right; i++) {
                    if (i != left) {
                        System.out.print("+");
                    }
                    System.out.print(i);
                }
                System.out.println("");
                tmp -= right;
                right--;
                left--;
                tmp += left;
                left--;
                tmp += left;
            }
        }
        System.out.println("Result:" + res);
    }
}
